/**********************************************
*  Namespace: AI
*  Classes:   SteeringWanderCircle
*  Desc:      Updates positions using a wander
*             inside a circle algorithm in 2d or
*             3d cases
*  Author:    Vaios Kalpias-Ilias (C) 2008-2009
***********************************************/

#include "SteeringWanderCircle.h"
#include "SteeringFace.h"
#include "Helper.h"

namespace AI
{
	//---------------------------------------------
	/**
	* Ctor
	*/
	SteeringWanderCircle::SteeringWanderCircle()
		:  wanderOffset(0.5f),
		   wanderRadius(4.0f),
		   wanderRate(10.1f),
		   wanderOrientation(0.0f)
	{
	}
	//---------------------------------------------
	/**
	* Dtor
	*/
	SteeringWanderCircle::~SteeringWanderCircle()
	{
	}
	//---------------------------------------------
	/**
	* Returns new kinematic data in 2d
	*/
	Steering2d SteeringWanderCircle::GetSteering(const Kinematic2d& current)
	{
		// update wander orientation
		wanderOrientation += mth::Helper::RandomBinomial() * wanderRate;

		// calculate combined target orientation
		float targetOrientation = wanderOrientation + current.orientation;

		// calculate center of wander circle
		Kinematic2d target(current);
		mth::Vector2 orientVector = mth::Helper::AsVector(current.orientation);
		target.position += orientVector * wanderOffset;

		// calculate target location
		target.position += wanderRadius * mth::Helper::AsVector(targetOrientation);

		// delegate to face
		Steering2d steering = SteeringFace::GetSteering(current, target);

		// set full acceleration to target
		steering.linear = maxAcceleration * orientVector;

		return steering;

	}

}
